<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>calculator</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .calculator {
        margin: 200px auto;
        width: 200px;
        height: 200px;
        border-radius: 16px;
        background-color: rgb(231, 231, 234);
      }
      input {
        width: 80%;
        height: 40px;
        margin: 20px 10px;
        background-color: #fff;
        font-size: 15px;
        border-radius: 6px;
        padding-left: 5px;
        padding-right:5px;
      }
      .operator {
        width: 200px;
        position: absolute;
      }
      button {
        width: 40px;
        height: 40px;
        border-radius: 16px;
        border-radius: inset 1px 1px 1px 1px rgb(0, 0, 0, 0.3);
        background-color: rgb(241, 246, 244);
        font-size: 16px;
      }
      .add {
        position: relative;
        left: 20px;
      }
      .substract {
        position: relative;
        left: 100px;
      }
    </style>
  </head>
  <body>
    <div class="calculator">
      <input type="text" placeholder="请输入数字" />
      <div class="operator">
        <button class="add">+</button>
        <button class="substract">-</button>
      </div>
    </div>
    <script>
      var cal = document.querySelector(".calculator");
      var input = document.querySelector("input");
      var operator = document.querySelector(".operator");
      input.onclick=function(){
        input.style.borderColor='#283155'
      }
      operator.addEventListener("click", function (e) {
        if (e.target.className == "add") {
          input.value++;
        }
        if (e.target.className == "substract") {
          input.value--;
        }
        var random1 = getRandom(0, 255);
        var random2 = getRandom(0, 255);
        var random3 = getRandom(0, 255);
        console.log(cal.style.backgroundColor );
        cal.style.backgroundColor = `rgb(${random1},${random2},${random3})`;
      });
      function getRandom(N, M) {
        return Math.floor(Math.random() * (M - N + 1)) + N;
      }
    </script>
  </body>
</html>
